package com.teamwork.ZuccEcho.Repository;

import com.teamwork.ZuccEcho.Entity.Student;
import com.teamwork.ZuccEcho.Entity.Teacher;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

@Repository
public interface LoginStuApiRepository extends JpaRepository<Student,Long> {
    @Query(value = "select stu_pwd from student where stu_id = ?1", nativeQuery = true)
    String searchPwdByStuId(String studentID);

    @Transactional
    @Modifying
    @Query(value="UPDATE student SET stu_phone = ?1 WHERE stu_id = ?2", nativeQuery = true)
    void modifyPhoneByStuId(String phone,String studentID);

    @Transactional
    @Modifying
    @Query(value="UPDATE student SET stu_pwd = ?1 WHERE stu_id = ?2 and stu_phone=?3", nativeQuery = true)
    void modifyPwdByPhone(String pwd,String studentID,String phone);

    @Transactional
    @Modifying
    @Query(value="UPDATE student SET stu_pwd = ?1 WHERE stu_id = ?2 and stu_pwd=?3", nativeQuery = true)
    void modifyPwdByOldPwd(String newpwd,String studentID,String oldpwd);


    @Query(value = "select * from student where stu_id=?1", nativeQuery = true)
    Student findStudentByStuid(String id);

    List<Student> findAll();
}
